/**
 * File: FileLocationsImpl.java
 * Created by: mhaimel
 * Created on: 16 Jul 2009
 * CVS:  $Id: FileLocationsImpl.java,v 1.4 2009/10/09 14:44:02 mhaimel Exp $
 */
package uk.ac.ebi.curtain.configuration.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import uk.ac.ebi.curtain.configuration.CurtainInputArguments;
import uk.ac.ebi.curtain.configuration.FileLocations;
import uk.ac.ebi.curtain.utils.StatisticHelper;
import uk.ac.ebi.curtain.utils.data.ReadType;

/**
 * @author mhaimel
 *
 */
public class FileLocationsImpl implements FileLocations {
	
	private final File baseDir;
	private final CurtainInputArguments arguments;
	public FileLocationsImpl(File dir, CurtainInputArguments args) {
		this.baseDir = dir;
		this.arguments = args;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getMaqDir() {
		return new File(baseDir,"maq_files");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getWorkingDir() {
		return baseDir;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getBucketDir() {
		return new File(baseDir,"bucket_coll");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getSuperContigFile() {
		String postStr = StringUtils.EMPTY;
		if(!arguments.getBatchList().isEmpty()){
			List<Integer> arrList = new ArrayList<Integer>(arguments.getBatchList());
			Collections.sort(arrList);
			Integer max = StatisticHelper.max(arrList);
			Integer min = arrList.get(0);
			Integer size = arrList.size();
			postStr = "_"+min+":"+max+"_"+size;
		}
		return new File(baseDir,"super_contig.fa"+postStr);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getConfigurationInformation() {
		return new File(baseDir,"file_config.xf.gz");
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getEntryFilePosition(ReadType type) {
		return new File(baseDir,"entry_position_"+type.name()+".xf.gz");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getEntryMapPosition(ReadType type) {
		return new File(baseDir,"entry_map_"+type.name()+".xf.gz");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public File getMappedData(ReadType type) {
		return new File(baseDir,"data_"+type.name()+".idx.gz");
	}

	@Override
	public File getIndexFile(ReadType type) {
		return new File(baseDir,"entry_id_"+type.name()+".idx.gz");
	}

	@Override
	public File getGraph(String type) {
		return new File(baseDir,type+"_graph");
	}

	@Override
	public File getLastGraph() {
		return getGraph("Last");
	}

	@Override
	public File getGraphStatistic(String type) {
		return new File(baseDir,type+"_stats.txt");
	}

	@Override
	public File getSequenceBoxMapping(ReadType type,Integer category,boolean fullMatch){
		return new File(baseDir,category+"_"+type +"_"+(fullMatch?"full":"partial")+".gz");
	}



}
